<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>系统管理</title>
</head>
<body>
<div class="box">
    <!-- /.box-header -->
    <section class="content">
        <div class="box-body">
            <form role="form">
                <!-- text input -->
                <div class="form-group col-md-7">
                    <label>分类名称</label>
                    <input type="text" id="category" class="form-control" placeholder="分类名 ...">
                </div>
                <div class="form-group col-md-7">
                    <label>几级分类</label>
                    <select id="select" class="form-control">
                        <option value="1" selected="selected">一级分类</option>
                        <option value="2">二级分类</option>
                    </select>
                </div>
                <div class="form-group col-md-7">
                    <label>上级分类</label>
                    <select id="select2" disabled="disabled" class="form-control">
                        <option value="0" selected="selected">选择二级分类在选择</option>
                        {volist name='list' id='v'}
                            <option value="{$v.id}">{$v.categoryname}</option>
                        {/volist}
                    </select>
                </div>
                <div class="form-group col-md-7">
                    <label>所属排序组</label>
                    <input type="text" id="sort" class="form-control" placeholder="例：nyt">
                </div>
                <div class="form-group col-md-7">
                    <div type="submit" id="btn_save" class="btn btn-info btn-flat pull-right">保存</div>
                </div>
            </form>
        </div>
        <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    $(function(){
        $('#select').click(function(){
            var _val = $(this).val();
            if(_val == 2){
                $('#select2').removeAttr('disabled');
            }
            if(_val == 1){
                $('#select2').attr('disabled','disabled');
                $('#select2').val('0');
            }
        })
        $('#btn_save').click(function(){
            var _category = $('#category').val();
            if(_category== ''){
                layerAlert('请输入分类名',function(){})
                return false;
            }
            var _select1 = $('#select').val();
            var _select2 = $('#select2').val();
            var _sort = $('#sort').val();
            $.ajax({
                type: 'post',
                url:'{:url("tencent/doCategory")}',
                data: {category:_category,select1:_select1,select2:_select2,sort:_sort},
                success: function(data) {
                    if(data.code=="0")
                    {
                        layerAlert('添加成功',function(){
                            parent.relist();
                            layerParentClose();
                        })
                    }
                },
                error: function() {
                    layerAlert('系统错误，请联系管理员');
                }

            });
        })
    })
</script>
</html>